package org.aphelie.torg.ruler.internal.ui.editor.character;

import org.aphelie.torg.ruler.core.IBaseModel;
import org.aphelie.torg.ruler.internal.ui.TGRUIMessages;
import org.aphelie.torg.ruler.internal.ui.editor.TGRFormEditorContributor;
import org.aphelie.torg.ruler.internal.ui.util.SWTUtil;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.custom.BusyIndicator;

public class CharacterEditorContributor extends TGRFormEditorContributor {

	private ExternalizeAction fExternalizeAction;

	class ExternalizeAction extends Action {
		public ExternalizeAction() {
		}

		public void run() {
			if (getEditor() != null) {
				BusyIndicator.showWhile(SWTUtil.getStandardDisplay(), new Runnable() {
					public void run() {
						//TODO GetNonExternalizedStringsAction externalizeAction = new GetNonExternalizedStringsAction();
						IStructuredSelection selection = new StructuredSelection(getEditor().getCommonProject());
						//TODO externalizeAction.runGetNonExternalizedStringsAction(selection);
					}
				});
			}
		}
	}

	public CharacterEditorContributor() {
		super("&Plugin"); //$NON-NLS-1$
	}

	public void contextMenuAboutToShow(IMenuManager mm, boolean addClipboard) {
		super.contextMenuAboutToShow(mm, addClipboard);
		IBaseModel model = getEditor().getAggregateModel();
		if (model != null && model.isEditable()) {
			mm.add(new Separator());
			mm.add(fExternalizeAction);
		}
	}

	protected void makeActions() {
		super.makeActions();
		fExternalizeAction = new ExternalizeAction();
		fExternalizeAction.setText(TGRUIMessages.CharacterEditorContributor_externStringsActionName);
	}

	public boolean supportsContentAssist() {
		return true;
	}

	public boolean supportsFormatAction() {
		return true;
	}

	public boolean supportsCorrectionAssist() {
		return true;
	}

	public boolean supportsHyperlinking() {
		return true;
	}

}
